'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.createTable('settings', {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER
      },
      key: {
        type: Sequelize.STRING(50),
        allowNull: false,
        unique: true,
        comment: '设置键名'
      },
      value: {
        type: Sequelize.TEXT,
        allowNull: true,
        comment: '设置值（JSON字符串）'
      },
      description: {
        type: Sequelize.STRING(255),
        allowNull: true,
        comment: '设置描述'
      },
      updatedBy: {
        type: Sequelize.STRING(50),
        allowNull: true,
        comment: '最后更新者'
      },
      createdAt: {
        allowNull: false,
        type: Sequelize.DATE
      },
      updatedAt: {
        allowNull: false,
        type: Sequelize.DATE
      }
    });

    // 添加索引
    await queryInterface.addIndex('settings', ['key'], {
      unique: true,
      name: 'settings_key_unique'
    });
  },

  async down(queryInterface, Sequelize) {
    await queryInterface.dropTable('settings');
  }
}; 